/**
 * Created by cjd on 2016/6/9.
 */
angular.module("app").controller("user.changePassword.Ctrl", ["$scope", "$http", "User", function ($scope, $http, User) {
    $scope.editPassword = function(){
        if($scope.newPW != $scope.newPW2){
            alert("两次输入的密码不一致,请重新输入!");
            return;
        }
        User.checkPassword({}, {password: $scope.password}, function (data) {
            if (data.statusCode == 0) {
                User.updatePassword({}, {password: $scope.newPW2}, function (data) {
                    if (data.statusCode == 0) {
                        alert("修改密码成功,请重新登录!");
                        sessionStorage.clear();
                        location.href = "#/login";
                    } else {
                        alert("原始密码错误,请重新输入!")
                    }
                })
            } else {
                alert("原始密码错误,请重新输入!")
            }
        })
    };
}]);